<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<script type="text/javascript">
	var form_url = base.contextPath+"/sysmgr/menu/add.do" ; 
	var s1, s2, s3, s4 ;
	$(function() {
		$("#s1").combobox({
			valueField: 'label', textField: 'value', value: 'R',
			data: [{ label: 'R', value: '导航栏目' },{ label: 'F', value: '导航菜单' },{ label: 'O', value: '菜单操作' }],
			panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(node){
				if("R" == node.label) {
					s3.combotree({ value: '', disabled: true }) ;
					s2.combobox({value: '', disabled: true, required: false});
					$("#mv").validatebox({required: false});
					$("#mv").attr("disabled", true) ;
					$("#href").validatebox({required: false});
					$("#href").attr("disabled",true) ;
				} else if("F" == node.label) {
					s3.combotree({disabled: false, required:true, autoShowPanel: true }) ;
					s2.combobox({disabled: true, required: false});
					$("#mv").validatebox({required: false});
					$("#mv").attr("disabled",true) ;
					$("#href").validatebox({required: false});
					$("#href").attr("disabled",false) ;
				} else if("O" == node.label) {
					s3.combotree({ disabled: false, required:true, autoShowPanel: true }) ;
					s2.combobox({ disabled: false, required: true});
					$("#mv").validatebox({required: true});
					$("#mv").attr("disabled",false) ;
					$("#href").validatebox({required: true});
					$("#href").attr("disabled",false) ;
				}
			}
	    });
		
		s2 = $("#s2").combobox({
			valueField: 'label', textField: 'value',
			data: [
			       { label: '页面', value: '页面' },{ label: '添加', value: '添加' },
			       { label: '删除', value: '删除' },{ label: '修改', value: '修改' },
			       { label: '查询', value: '查询' },{ label: '其他', value: '其他' }
			],
			panelHeight:'auto', editable:false, autoShowPanel: true
	    });
		s3 = $("#s3").combotree({
			url : base.contextPath+"/sysmgr/menu/doNotNeedAuth_combotree.do",
			idFiled:'pid', textFiled:'name', editable: false,
			disabled: true, required:false, lines:true, autoShowPanel: false
	    });  
		
		s4 = $("#s4").combobox({
			valueField: 'label', textField: 'value', value: '0',
			data: [{ label: '0', value: '显示' },{ label: '1', value: '不显示' }],
			panelHeight:'auto', editable:false, autoShowPanel: true
	    });
		
		$("#state").combobox({
			valueField: 'label', textField: 'value', value: 'open',
			data: [{ label: 'closed', value: '是' },{ label: 'open', value: '否' }],
			panelHeight:'auto', editable:false, autoShowPanel: true
	    });
		
		$("#target").combobox({
			valueField: 'label', textField: 'value', value: 'mainFrame',
			data: [
			       { label: 'mainFrame', value: 'mainFrame' },{ label: '_blank', value: '_blank' },
			       { label: '_self', value: '_self' },{ label: '_parent', value: '_parent' },
			       { label: '_top', value: '_top' }
			],
			panelHeight:'auto', editable:false, autoShowPanel: true
	    });
		
		//编辑，加载表单数据
		if($('input[name=id]').val().length > 0) {
			form_url = base.contextPath+"/sysmgr/menu/edit.do" ;
			$.post(base.contextPath+"/sysmgr/menu/doNotNeedAuth_get.do", {id:$('input[name=id]').val()}, function(result) {
				if (result.id != undefined) {
					$('form').form('load', {
						'id' : result.id,
						'name' : result.name,
						'href' : result.href,
						'action_value' : result.action_value,
						'permitCode' : result.permitCode,
						'sort' : result.sort,
						'type' : result.type,
						'iconCls' : result.iconCls,
						'pid' : result.pid,
						'remark' : result.remark,
						'isShow': result.isShow
					});
					
					if("R" == result.type) {
						s3.combotree({ value: '', disabled: true }) ;
						s2.combobox({value: '', disabled: true, required: false});
						$("#mv").validatebox({required: false});
						$("#mv").attr("disabled", true) ;
						$("#href").validatebox({required: false});
						$("#href").attr("disabled",true) ;
					} else if("F" == result.type) {
						s3.combotree({ disabled: false, required:true, value: result.pid }) ;
						s2.combobox({disabled: true, required: false});
						$("#mv").validatebox({required: false});
						$("#mv").attr("disabled",true) ;
						$("#href").validatebox({required: false});
						$("#href").attr("disabled",false) ;
					} else if("O" == result.type) {
						s3.combotree({ disabled: false, required:true, value: result.pid }) ;
						s2.combobox({ disabled: false, required: true, value: result.action_value});
						$("#mv").validatebox({required: true});
						$("#mv").attr("disabled",false) ;
						$("#href").validatebox({required: true});
						$("#href").attr("disabled",false) ;
					}
				}
			}, 'json');
		} else {
			s3.combotree({ disabled: true, required:false, autoShowPanel: true }) ;
			s2.combobox({value: '', disabled: true});
		}
		$("#mv").validatebox({required: false});
		$("#mv").attr("disabled", true) ;
		$("#href").attr("disabled", true) ;
		s2.combobox({disabled: true});
	});
	
	//提交表单数据
	var submitNow = function($d, $tg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$tg.treegrid("reload");
				$.easyui.loading({ msg: "正在加载...", locale: "#westCenterLayout", topMost: true });
				$.util.exec(function () { 
					$.easyui.parent.window.mainpage.refreshNavTab(); 
					$.easyui.loaded(true);
					$.easyui.loaded(); 
				},2000);
				alertify.success(result.msg);
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
			}
		}, 'json').error(function(){$.easyui.loaded();});
	};
	
	//验证表单
	var submitForm = function($d, $tg, flag) {
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $tg, flag) ;
		} 
	};
</script>
<form id="form" class="easyui-form form_container">
	<input type="hidden" name="id" value="${id}" />
	<input type="hidden" name="modifyName" value="${USER_SESSION.truename}" />
	<table class="tableform">
		<tr>
			<th>菜单名称：</th>
			<td><input name="name" class="easyui-validatebox" type="text" data-options="required: true, prompt: '菜单名称'" /></td>
			<th>菜单类型：</th>
			<td><input id="s1" name="type" style="width:218px;height:30px;"></input></td>
		</tr>
		<tr>
			<th>权限代码：</th>
			<td><input id="mv" name="permitCode" class="easyui-validatebox" type="text" /></td>
			<th>动作：</th>
			<td>
				<input id="s2" name="action_value" style="width:218px;height:30px;"></input>
			</td>
		</tr>
		<tr>
			<th>URL地址：</th>
			<td colspan="3"><input id="href" name="href" class="easyui-validatebox" style="width:580px;" type="text" data-options="required: false, prompt: '菜单地址'" /></td>
		</tr>
		<tr>
			<th>父菜单：</th>
			<td><input id="s3" name="pid" style="width:218px;height:30px;"></input><a onClick="s3.combotree('setValue','');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_clear'"></a></td>
			<th>是否显示：</th>
			<td><input id="s4" name="isShow" style="width:218px;height:30px;"></input></td>
		</tr>
		<tr>
			<th>排序：</th> 
			<td><input name="sort" class="easyui-numberspinner" value="100" type="text" data-options="min:1,max:999" style="width:218px;height:30px;" /></td>
			<th>图标：</th>
			<td><input name="iconCls" class="easyui-comboicons" data-options="autoShowPanel: false, multiple: false, size: '16', value: 'icon-standard-application-view-list'" style="width:218px;height:30px;" /></td>
		</tr>
		<tr>
			<th>是否展开：</th>
			<td><input id="state" name="state" style="width:218px;height:30px;"></td>
			<th>打开目标：</th>
			<td><input id="target" name="target" style="width:218px;height:30px;"></td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea name="remark" rows="5" cols="5" style="border:1px solid #A5AEB6;width:689px;height:85px;max-width:689px;min-width:689px;max-height:85px;min-height:85px;"></textarea>
			</td>
		</tr>
	</table>
</form>
